package net.yiny.scrummer.ui.storyboard

import net.yiny.scrummer.model.Card
import net.yiny.scrummer.model.PhaseStrip


public class PhaseStripControllerFactory {

    def createController(PhaseStrip phaseStrip, CardControllerFactory cardFactory) {
        if (!phaseStrip) { throw new IllegalArgumentException("Phase strip is null") }
        if (!cardFactory) { throw new IllegalArgumentException("Card factory is null") }
        def builder = new PhaseStripBuilder()
        def controller = new PhaseStripController(builder: builder, phaseStrip: phaseStrip)
        phaseStrip.cards.each {controller.children += cardFactory.createController(it)}
        controller.children.each {builder.children += it.builder}
        builder.addListener controller
        controller
    }

    def addCard(PhaseStripController controller, CardControllerFactory cardFactory, Card newCard) {
        def newCardController = cardFactory.createController(newCard)
        controller.children += newCardController
        controller.builder.children += newCardController.builder
    }
}